package cn.pcManage.userManage.service.impl;

import cn.common.common.model.ServerResponse;
import cn.common.user.model.BaseUserInfo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import cn.pcManage.userManage.dao.UserInfoMapper;
import cn.pcManage.userManage.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Zhang on 2019/1/7.
 */
@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    UserInfoMapper userInfoMapper;


    @Override
    public ServerResponse<?> getUserList(BaseUserInfo userInfo) {
        Map<String,Object> resultMap=new HashMap<String, Object>(2);
        PageHelper.startPage(userInfo.getPage(),userInfo.getLimit());
        List<BaseUserInfo> userInfoList = userInfoMapper.getUserList(userInfo);
        Page<BaseUserInfo> userInfoPage = (Page<BaseUserInfo>) userInfoList;
        long total = userInfoPage.getTotal();
        resultMap.put("total", total);
        resultMap.put("infos", userInfoList);
        return ServerResponse.createBySuccess(resultMap);
    }

    @Override
    public ServerResponse<?> deleteUser(Integer userid) {
        BaseUserInfo userInfo = userInfoMapper.selectByPrimaryKey(userid);
        userInfo.setStatus("禁用");
        userInfoMapper.updateByPrimaryKeySelective(userInfo);
        return ServerResponse.createBySuccessMessage("操作成功");
    }
}
